package com.neouton.crm.managerRefundRecords.service.impl;


import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.neouton.common.entity.ActivitiVO;
import com.neouton.common.util.*;
import com.neouton.crm.approval.entity.ApprovalVO;
import com.neouton.crm.approval.service.IApprovalService;
import com.neouton.crm.dictionary.entity.DictionaryLookupItemVO;
import com.neouton.crm.dictionary.service.IDictionaryService;
import com.neouton.crm.entity.SysUserEntity;
import com.neouton.crm.managerPayRecord.entity.ManagerPayRecord;
import com.neouton.crm.managerPayRecord.mapper.ManagerPayRecordMapper;
import com.neouton.crm.refundRecords.entity.RefundRecordsVO;
import com.neouton.crm.managerRefundRecords.mapper.ManagerRefundRecordsMapper;
import com.neouton.crm.managerRefundRecords.service.ManagerRefundRecordsService;
import com.neouton.crm.payRecords.entity.PaymentRecords;
import com.neouton.crm.pm.entity.PurchaseOrderVO;
import com.neouton.crm.pm.service.IPurchaseOrdeService;
import com.neouton.crm.transpondEmail.entity.TranspondEmailVO;
import com.neouton.crm.transpondEmail.mapper.TranspondEmailMapper;
import com.neouton.crm.transpondEmail.service.TranspondEmailService;
import com.neouton.feginClient.FeginService;
import com.neouton.feginClient.WorkFlowFeginService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.CompletableFuture;

@Service
public class ManagerManagerRefundRecordsServiceImpl implements ManagerRefundRecordsService {


    @Resource
    private ManagerRefundRecordsMapper managerRefundRecordsMapper;

    @Resource
    private IDictionaryService dictionaryService;

    @Resource
    private IPurchaseOrdeService purchaseOrdeService;

    @Resource
    private ManagerPayRecordMapper managerPayRecordsMapper;
    @Resource
    private FeginService feginService;

    @Resource
    private TranspondEmailService transpondEmailService;

    @Value("${webSit.web}")
    private String webSitUrl;

    @Resource
    private WorkFlowFeginService workFlowFeginService;

    @Resource
    private IApprovalService approvalService;

    @Resource
    private TranspondEmailMapper transpondEmailMapper;
    /**
     * 启动工作流
     * @param refundRecords
     * @return
     */
    public int startWorkFlow(RefundRecordsVO refundRecords){
        ActivitiVO activitiVO = new ActivitiVO();
        activitiVO.setAuthorization(AuthUtils.getUserAccount());
        activitiVO.setProcessName("行政退款记录审批流程");
        activitiVO.setProcessCode("manager_refund_approval");
        activitiVO.setNextNodeParams("personnelManager");
        //获取下一步人员信息注入；人事信息
        SysUserEntity personnelManager = dictionaryService.queryMenuUserIdsByCode("personnelManager").get(0);
        activitiVO.setNextNodeAssignee(personnelManager.getAccount());
        // 启动工作流
        ResponseAPI<ActivitiVO> responseAPI = workFlowFeginService.startMaxVersionProcessByDesignCodeCustomParams(activitiVO);
        ApprovalVO approval = approvalService.initApprovalAndLog(responseAPI.getResult().getBusinessId(),
                Constants.REFUND_MANAGER_TASK_TYPE, refundRecords.getReason(), "",personnelManager.getUserId(),"");

        return approval.getApprovalId();
    }
    @Override
    public int saveOrUpdateCustomer(RefundRecordsVO refundRecords, String token) {
        String paymentMoney1 = null;
        //获取付款记录
        List<ManagerPayRecord> paymentRecords = managerPayRecordsMapper.getPayRecords();

        for (ManagerPayRecord paymentRecord : paymentRecords) {
            if (paymentRecord.getApproval().getApprovalStatus() != 1 && paymentRecord.getPayRecordsId().equals(refundRecords.getPayRecordsId())) {
                return -401;
            }

            if (paymentRecord.getPayRecordsId().equals(refundRecords.getPayRecordsId())){
                paymentMoney1 = paymentRecord.getPaymentMoney();
            }
        }
        //退还金额
        Double refundRecordSum = managerRefundRecordsMapper.getPayMoneySum(refundRecords);
        if (refundRecordSum == null){
            refundRecordSum = 0.00;
        }

        //付款金额
        Double paymentMoney = Double.parseDouble(paymentMoney1);
        Double nowRefundMoney = Double.parseDouble(refundRecords.getRefundMoney());
        // flushMoney空字符串处理
        if ("".equals(refundRecords.getFlushMoney())){
            refundRecords.setFlushMoney(null);
        }
        if (null == refundRecords.getId()) {
            if (paymentMoney < refundRecordSum + nowRefundMoney) {
                return -501;
            }
            refundRecords.setApprovalId(this.startWorkFlow(refundRecords));
            refundRecords.setCreator(AuthUtils.getUserId());
            managerRefundRecordsMapper.saveRefundInfo(refundRecords);
        } else {
            Double oldRefundMoney = Double.parseDouble(managerRefundRecordsMapper.selectRefundById(refundRecords.getId()).getRefundMoney());
            if (paymentMoney < refundRecordSum + nowRefundMoney - oldRefundMoney) {
                return -501;
            }
            refundRecords.setApprovalId(this.startWorkFlow(refundRecords));
            refundRecords.setLastUpdateBy(AuthUtils.getUserId());
            managerRefundRecordsMapper.updateRefundInfo(refundRecords);
        }

        //         转发人记录
        if (refundRecords.getTranspondUseIdList() != null && refundRecords.getTranspondUseIdList().size() > 0){
            TranspondEmailVO transpondEmailVO = new TranspondEmailVO();
            transpondEmailVO.setApprovalId(refundRecords.getApprovalId());
            transpondEmailVO.setTranspondUseIdList(refundRecords.getTranspondUseIdList());
            transpondEmailMapper.insertTranspondEmailInfo(transpondEmailVO);
        }

        SysUserEntity personnelManager = dictionaryService.queryMenuUserIdsByCode("personnelManager").get(0);
        if (personnelManager.getUserId().equals(AuthUtils.getUserId())){
            //跳过第一步审批
            this.approveRefundRecords(refundRecords,token, true);
        }else{
            CompletableFuture.runAsync(() -> NoticUtils.pushNotic(refundRecords.getApprovalId(),  new Timestamp(System.currentTimeMillis()), refundRecords.getCreator(),
                    Constants.WORK_STATE_START,Constants.REFUND_MANAGER_TASK_TYPE,personnelManager.getUserId(),token));
        }
        return refundRecords.getId();
    }

    /**
     * 审批通过
     * @param refundRecords
     * @return 成功失败
     */
    @Transactional
    public Boolean approveRefundRecords(RefundRecordsVO refundRecords,String token,Boolean auto) {

        ApprovalVO approval = approvalService.queryApprovalByAppID(refundRecords.getApprovalId());
        ActivitiVO activitiVO = new ActivitiVO();
        activitiVO.setAuthorization(AuthUtils.getUserAccount());
        activitiVO.setBusinessId(approval.getBusinessId());
        //获取当前所处节点
        ResponseAPI<ActivitiVO> processNodeNameAndCode = workFlowFeginService.getProcessNodeNameAndCode(activitiVO);

        //记录审批日志
        if(auto){
            approvalService.insertApprovalLog(refundRecords.getApprovalId(),"通过",
                    "系统判定跳过",refundRecords.getAuditOpinion());
        }else {
            //记录日志
            approvalService.insertApprovalLog(refundRecords.getApprovalId(),"通过",
                    "",refundRecords.getAuditOpinion());
        }
        if ("人事经理".equals(processNodeNameAndCode.getResult().getName())){
            //会计信息
            SysUserEntity finance = dictionaryService.queryMenuUserIdsByCode("finance").get(0);
            activitiVO.getCustomParams().put("finance",finance.getAccount());

            //审批通过（使用动态入参传入下一审批人）
            workFlowFeginService.approvalProcessCustomUserByBusinessId(activitiVO);
            //获取下一节点
            ResponseAPI<ActivitiVO> nextProcessNodeNameAndCode = workFlowFeginService.getProcessNodeNameAndCode(activitiVO);
            if(nextProcessNodeNameAndCode.getResult().getAssignee().equals(processNodeNameAndCode.getResult().getAssignee())){ //记录日志
                this.approveRefundRecords(refundRecords,token,true);
            }else {
                approvalService.updateNextApproverByApprovalId(finance.getUserId(), refundRecords.getApprovalId());
                CompletableFuture.runAsync(() -> NoticUtils.pushNotic(refundRecords.getApprovalId(),  new Timestamp(System.currentTimeMillis()), refundRecords.getCreator(),
                        Constants.WORK_STATE_START,Constants.REFUND_MANAGER_TASK_TYPE,finance.getUserId(),token));
            }
        }else {
            workFlowFeginService.approvalProcessByBusinessId(activitiVO);
            approvalService.approved(null, refundRecords.getApprovalId());
            apSendEmailAndPushNotice(refundRecords, token);
        }
        return true;
    }
    /**
     * 审批驳回
     * @param refundRecords
     * @return
     */
    @Transactional
    public Boolean rejectionRefundRecords(RefundRecordsVO refundRecords,String token) {
        ApprovalVO approval = approvalService.queryApprovalByAppID(refundRecords.getApprovalId());
        ActivitiVO activitiVO = new ActivitiVO();
        activitiVO.setAuthorization(AuthUtils.getUserAccount());
        activitiVO.setBusinessId(approval.getBusinessId());
        // 删除实例，驳回至起点
        workFlowFeginService.deleteInstance(activitiVO);
        CompletableFuture.runAsync(() ->  NoticUtils.pushNotic(refundRecords.getApprovalId(), refundRecords.getLastUpdateTime(), refundRecords.getCreator(),
                Constants.WORK_STATE_STOP,Constants.REFUND_MANAGER_TASK_TYPE,0,token));
        approvalService.insertApprovalLog(refundRecords.getApprovalId(), "驳回",
                "", refundRecords.getAuditOpinion());
        return approvalService.approvalRejection(null, refundRecords.getApprovalId());
    }


    public void apSendEmailAndPushNotice(RefundRecordsVO refundRecords,String token){
        if (refundRecords.getAuditOpinion() == null || refundRecords.getAuditOpinion().isEmpty()){
            refundRecords.setAuditOpinion("无");
        }
        //获取人员信息
        SysUserEntity user = feginService.searchUserInfoByIds(refundRecords.getCreator(), token).getResult();
        //发送邮件
        String titel = "【系统通知】行政退款记录 - 流程单审批通过通知";
        String msg = "<div>"
                + "<p> 尊敬的" + user.getLoginName() + " ：<br></p ></div>"
                + "<p> &nbsp; &nbsp; &nbsp; 您好，您提交的行政退款记录已通过：</p>"
                + "<p> &nbsp; &nbsp; &nbsp; 退款名称："+refundRecords.getRefundTopic() + "<p>"
                + "<p> &nbsp; &nbsp; &nbsp; 审批人："+AuthUtils.getUserName() + " / " + AuthUtils.getUserAccount() +"<p>"
                + "<p> &nbsp; &nbsp; &nbsp; 审批时间："+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())+ "<p>"
                + "<p> &nbsp; &nbsp; &nbsp; 审批意见："+refundRecords.getAuditOpinion()+ "<p>"
                + "<p> &nbsp; &nbsp; &nbsp; 系统查看路径：客户关系管理系统 - 行政采购管理 - 退款记录 " +
                "<a href='"+webSitUrl+"/?m=crm&p=executiveManager&me=managerRefundRecordInfo'>进入</a></p>"
                + "<div><p style='text-indent: 2em'>谢谢！</p>"
                + "<p> &nbsp; &nbsp; &nbsp; 说明：该邮件为系统自动发送，请勿回复。<p>";
        //获取抄送
        String emailList = selectCC(refundRecords);
        CompletableFuture.runAsync(() -> EmailUtils.sentMailByAddressee(user.getEmail(),emailList,titel,msg,token));
        //调用通知接口
        CompletableFuture.runAsync(() -> NoticUtils.pushNotic(refundRecords.getApprovalId(), new Timestamp(System.currentTimeMillis()), refundRecords.getCreator(),
                Constants.WORK_STATE_STOP,Constants.REFUND_MANAGER_TASK_TYPE,0,token));
    }


    public String selectCC(RefundRecordsVO refundRecords){
        //获取抄送人
        List<SysUserEntity> userIds = dictionaryService.queryCcUserIdsByCode("managerRefundRecordCC");
        StringBuilder emailList = new StringBuilder();
        for (int i = 0; i < userIds.size(); i++) {
            if (userIds.size()-1 == i){
                emailList.append(userIds.get(i).getEmail());
            }else {
                emailList.append(userIds.get(i).getEmail());
                emailList.append(",");
            }
        }
        String stringBuilder = transpondEmailService.selectTranspondEmailStr(refundRecords.getApprovalId());
        if (stringBuilder.length() > 0 && emailList.length() > 0){
            emailList.append(",");
            emailList.append(stringBuilder);
        }
        if (stringBuilder.length() > 0 && emailList.length() == 0){
            emailList.append(stringBuilder);
        }
        return emailList.toString();
    }


    @Override
    public PageUtil<RefundRecordsVO> getRedListByPage(IPage<RefundRecordsVO> page, RefundRecordsVO refundRecords, String orderBy, String token) {
        IPage<RefundRecordsVO> redListByPage = new Page<>();
        ApprovalVO approvalVO = new ApprovalVO();
        approvalVO.setApprovalType(Constants.REFUND_MANAGER_TASK_TYPE);
        List<ApprovalVO>  appList = new ArrayList<>();
        Boolean aBoolean = true;
        if ("todo".equals(refundRecords.getParamType())){
            appList = approvalService.queryApprovalByPage(approvalVO);
        }else if ("done".equals(refundRecords.getParamType())){
            appList = approvalService.queryApprovalDoneRecordByType(approvalVO);
        }else if ("record".equals(refundRecords.getParamType())){
            appList = approvalService.queryApprovalRecordByType(approvalVO,token);
        }else {
            aBoolean = false;
            List<SysUserEntity> authUserIList = dictionaryService.queryAuthUserIdsByCode("managerRefundRecord");
            Boolean result = false;
            for (SysUserEntity item : authUserIList) {
                if (item.getUserId().equals(AuthUtils.getUserId())) {
                    result = true;
                    break;
                }
            }
            if (!result) {
                if (AuthUtils.getUserId().equals(refundRecords.getCreator()) || refundRecords.getCreator() == null) {
                    refundRecords.setCreator(AuthUtils.getUserId());
                } else {
                    refundRecords.setCreator(-1);
                }
            }
        }
        if (aBoolean){
            if (appList != null && appList.size() > 0){
                ArrayList<Integer> arrayList = new ArrayList<>();
                for (ApprovalVO item:appList) {
                    arrayList.add(item.getApprovalId());
                }
                refundRecords.setApprovalIdList(arrayList);
            }else{
                return new PageUtil(redListByPage);
            }
        }
        redListByPage = managerRefundRecordsMapper.getRedListByPage(page, refundRecords, orderBy);
        List<RefundRecordsVO> records = redListByPage.getRecords();
        //crm 字典
        List<String> codes = new ArrayList<>();
        codes.add("receiveInvoice");
        codes.add("payMethod");
        codes.add("refundTypeList");
        Map<String, List<DictionaryLookupItemVO>> stringListMap = dictionaryService.queryDictionaryLookupInfo(null, codes);
        // 获取所有人信息
        List<SysUserEntity> allUsers = feginService.getUserIgnoreFlag(token).getResult();
        if(!records.isEmpty()){
            BigDecimal refundMoneyPage = new BigDecimal("0");
            for (RefundRecordsVO item: records) {

                String stringBuilder = transpondEmailService.selectTranspondNameStr(item.getApprovalId());
                item.setTranspondUseListStr(stringBuilder);
                if(!StringUtils.isEmpty(item.getRefundMoney())){
                    refundMoneyPage = refundMoneyPage.add(new BigDecimal(item.getRefundMoney()));
                }
                for (DictionaryLookupItemVO dictionaryLookupItemVO : stringListMap.get("receiveInvoice")) {
                    if (dictionaryLookupItemVO.getItemCode().equals(item.getIsInvoice().toString())) {
                        item.setIsInvoiceName(dictionaryLookupItemVO.getItemName());
                        break;
                    }
                }

                for (DictionaryLookupItemVO dictionaryLookupItemVO : stringListMap.get("payMethod")) {
                    if (dictionaryLookupItemVO.getItemCode().equals(item.getRefundMethod().toString())) {
                        item.setRefundMethodName(dictionaryLookupItemVO.getItemName());
                        break;
                    }
                }


                for (SysUserEntity item2 : allUsers) {
                    if (item2.getUserId().equals(item.getManagement())) {
                        item.setManagementName(item2.getLoginName());
                        item.setManagementAccount(item2.getAccount());
                    }
                    if (item2.getUserId().equals(item.getCreator())) {
                        item.setCreatorName(item2.getLoginName());
                        item.setCreatorAccount(item2.getAccount());
                    }
                }
                item.setCreateDataTimeStr(String.format("%tY-%<tm-%<td",item.getCreateDataTime()));
            }
            records.get(0).setRefundMoneyPage(String.valueOf(refundMoneyPage));
            redListByPage.setRecords(records);
        }

        return new PageUtil(redListByPage);
    }

    @Override
    public void exportRef(HttpServletResponse response, RefundRecordsVO refundRecords, String token) throws Exception {
        List<SysUserEntity> authUserIList = dictionaryService.queryAuthUserIdsByCode("managerRefundRecord");
        Boolean result = false;
        for (SysUserEntity item:authUserIList) {
            if (item.getUserId().equals(AuthUtils.getUserId())){
                result = true;
                break;
            }
        }
        if (!result){
            if (AuthUtils.getUserId().equals(refundRecords.getCreator()) || refundRecords.getCreator() == null) {
                refundRecords.setCreator(AuthUtils.getUserId());
            } else {
                refundRecords.setCreator(-1);
            }
        }
        List<RefundRecordsVO> refList = managerRefundRecordsMapper.getRedList(refundRecords);

        //crm 字典
        List<String> codes = new ArrayList<>();
        codes.add("receiveInvoice");
        codes.add("payMethod");
        codes.add("refundTypeList");
        codes.add("approvalStatus");
        Map<String, List<DictionaryLookupItemVO>> stringListMap = dictionaryService.queryDictionaryLookupInfo(null, codes);
        // 获取所有人信息
        List<SysUserEntity> allUsers = feginService.getUserIgnoreFlag(token).getResult();
        int i = 1;
        for (RefundRecordsVO item : refList) {

            for (DictionaryLookupItemVO dictionaryLookupItemVO : stringListMap.get("receiveInvoice")) {
                if (dictionaryLookupItemVO.getItemCode().equals(item.getIsInvoice().toString())) {
                    item.setIsInvoiceName(dictionaryLookupItemVO.getItemName());
                    break;
                }
            }

            for (DictionaryLookupItemVO dictionaryLookupItemVO : stringListMap.get("payMethod")) {
                if (dictionaryLookupItemVO.getItemCode().equals(item.getRefundMethod().toString())) {
                    item.setRefundMethodName(dictionaryLookupItemVO.getItemName());
                    break;
                }
            }


            for (SysUserEntity item2 : allUsers) {
                if (item2.getUserId().equals(item.getManagement())) {
                    item.setManagementName(item2.getLoginName());
                    item.setManagementAccount(item2.getAccount());
                }
                if (item2.getUserId().equals(item.getCreator())) {
                    item.setCreatorName(item2.getLoginName());
                    item.setCreatorAccount(item2.getAccount());
                }
            }

            for (DictionaryLookupItemVO dictionaryLookupItemVO : stringListMap.get("approvalStatus")) {
                if (dictionaryLookupItemVO.getItemCode().equals(item.getApprovalStatus().toString())) {
                    item.setApprovalStatusStr(dictionaryLookupItemVO.getItemName());
                    break;
                }
            }
            item.setId(i);
            item.setRefundDateStr(String.format("%tY-%<tm-%<td",item.getRefundDate()));
            item.setCreateDataTimeStr(String.format("%tY-%<tm-%<td",item.getCreateDataTime()));
            item.setPlanPeriod("第" + item.getPlanPeriod() + "期");
            i++;
        }


        //获取yml模板位置
        YamlPropertiesFactoryBean factoryBean = new YamlPropertiesFactoryBean();
        String path = "application.yml";
        factoryBean.setResources(new ClassPathResource(path));
        Properties properties = factoryBean.getObject();
        String contractTemplatePath = String.valueOf(properties.get("report.managerRefundRecordTemplate"));

        //依据根目录获取模板位置
        TemplateExportParams params = new TemplateExportParams(contractTemplatePath);
        Map<String, Object> map = new HashMap<>();
        map.put("vo",refList);
        ReportUtils.exportExcel(params,map,"行政退款记录",response);
    }

    @Override
    public Double getPayMoneySum(RefundRecordsVO refundRecords, String token) {
        Double refundRecordSum = managerRefundRecordsMapper.getPayMoneySum(refundRecords);
        return refundRecordSum;
    }

    @Override
    public List<ManagerPayRecord> getPayRecords() {
        List<ManagerPayRecord> paymentRecords = managerPayRecordsMapper.getPayRecords();
        return paymentRecords;
    }

    @Override
    public Boolean deleteRefund(Integer refundId,String token) {
        RefundRecordsVO refundRecords = managerRefundRecordsMapper.selectRefundById(refundId);
        if (refundRecords.getIsDelete() == 0){
            return false;
        }
        Boolean status = managerRefundRecordsMapper.deleteRefundById(refundId);
        List<SysUserEntity> userIds = dictionaryService.queryCcUserIdsByCode("managerRefundRecordCC");
        StringBuilder emailList = new StringBuilder();
        for (int i = 0; i < userIds.size(); i++) {
            if (userIds.size()-1 == i){
                emailList.append(userIds.get(i).getEmail());
            }else {
                emailList.append(userIds.get(i).getEmail());
                emailList.append(",");
            }
        }
        String titel = "【系统通知】退款记录通知";
        String msg = "<div>"
                + "<p> 尊敬的" + userIds.get(0).getLoginName() + " ：<br></p ></div>"
                + "<p> &nbsp; &nbsp; &nbsp; 您好，" + AuthUtils.getUserName()  + "删除退款记录信息如下：</p>"
                + "<p> &nbsp; &nbsp; &nbsp; 退款名称："+refundRecords.getRefundTopic() + "<p>"
                + "<p> &nbsp; &nbsp; &nbsp; 退款金额："+refundRecords.getRefundMoney() + "元<p>"
                + "<div><p style='text-indent: 2em'>谢谢！</p>"
                + "<p> &nbsp; &nbsp; &nbsp; 说明：该邮件为系统自动发送，请勿回复。<p>";
        CompletableFuture.runAsync(() -> EmailUtils.sentMailByAddressee(userIds.get(0).getEmail(),emailList.toString(),titel,msg,token));
        return status;
    }

    /**
     * 通过审批ID查询退款记录信息
     * @param approvalId
     * @return
     */
    @Override
    public RefundRecordsVO getRefundInfoByApprovalId(Integer approvalId, String token) {
        RefundRecordsVO recordsVO = managerRefundRecordsMapper.getRefundInfoByApprovalId(approvalId);
        String stringBuilder = transpondEmailService.selectTranspondNameStr(approvalId);
        if (stringBuilder != null || stringBuilder.length() != 0){
            recordsVO.setTranspondUseListStr(stringBuilder);
        }
        //crm 字典
        List<String> codes = new ArrayList<>();
        codes.add("receiveInvoice");
        codes.add("payMethod");
        codes.add("refundTypeList");
        Map<String, List<DictionaryLookupItemVO>> stringListMap = dictionaryService.queryDictionaryLookupInfo(null, codes);
        for (DictionaryLookupItemVO dictionaryLookupItemVO : stringListMap.get("receiveInvoice")) {
            if (dictionaryLookupItemVO.getItemCode().equals(recordsVO.getIsInvoice().toString())) {
                recordsVO.setIsInvoiceName(dictionaryLookupItemVO.getItemName());
                break;
            }
        }

        for (DictionaryLookupItemVO dictionaryLookupItemVO : stringListMap.get("payMethod")) {
            if (dictionaryLookupItemVO.getItemCode().equals(recordsVO.getRefundMethod().toString())) {
                recordsVO.setRefundMethodName(dictionaryLookupItemVO.getItemName());
                break;
            }
        }

        // 获取所有人信息
        List<SysUserEntity> allUsers = feginService.getUserIgnoreFlag(token).getResult();
        for (SysUserEntity item2 : allUsers) {
            if (item2.getUserId().equals(recordsVO.getManagement())) {
                recordsVO.setManagementName(item2.getLoginName());
                recordsVO.setManagementAccount(item2.getAccount());
            }
            if (item2.getUserId().equals(recordsVO.getCreator())) {
                recordsVO.setCreatorName(item2.getLoginName());
                recordsVO.setCreatorAccount(item2.getAccount());
            }
        }
        recordsVO.setCreateDataTimeStr(String.format("%tY-%<tm-%<td",recordsVO.getCreateDataTime()));


        return recordsVO;
    }

}




